﻿using System.Xml;
using UnityEngine;
using System.Collections;

public class ReadXml
{

    public static ReadXml _instance = new ReadXml();

    private XmlDocument ReadAndLaodTextInfo()
    {
        XmlDocument doc = new XmlDocument();

        TextAsset textAsset = (TextAsset)Resources.Load("textass");

        doc.LoadXml(textAsset.text);

        return doc;
    }

    /// <summary>
    /// 传入ID来取这一行的对话信息
    /// </summary>
    /// <param name="id"></param>
    /// <returns>TextInfo</returns>
    public TextInfo GetContentById(int id)
    {
        TextInfo info = new TextInfo();

        XmlDocument xmlDoc = ReadAndLaodTextInfo();

        XmlNodeList textass = xmlDoc.SelectNodes("Content/textass");

        foreach (XmlNode textvalue in textass)
        {
            if (id == int.Parse(textvalue.Attributes["id"].Value))
            {
                info.id = int.Parse(textvalue.Attributes["id"].Value);
                info.itemType = byte.Parse(textvalue.Attributes["type"].Value);
                info.system = textvalue.Attributes["system"].Value;
                info.restart = int.Parse(textvalue.Attributes["restart"].Value);
                info.nextid1 = int.Parse(textvalue.Attributes["nextidA"].Value);
                info.nextid2 = int.Parse(textvalue.Attributes["nextidB"].Value);
                info.health1 = int.Parse(textvalue.Attributes["healthA"].Value);
                info.health2 = int.Parse(textvalue.Attributes["healthB"].Value);
                info.text1 = textvalue.Attributes["textA"].Value;
                info.text2 = textvalue.Attributes["textB"].Value;
            }
        }
        return info;
    }
}


public class TextInfo
{
    public int id;
    public byte itemType;
    public string system;
    public int restart;
    public int nextid1;
    public int nextid2;
    public int health1;
    public int health2;
    public string text1;
    public string text2;
}